/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmConjunto.java
 *
 * Created on 03-12-2014, 08:49:35 AM
 */
package presentacion;

import Negocios.Conjunto;
import Negocios.Entero;
import Negocios.VectorEntero;import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Estudiante
 */
public class FrmConjunto extends javax.swing.JFrame {

    /** Creates new form FrmConjunto */
    public FrmConjunto() {
        initComponents();
        
        this.DimencionarA(3);
        this.DimencionarB(3);
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btnUnion = new javax.swing.JButton();
        btnInterseccion = new javax.swing.JButton();
        btnAB = new javax.swing.JButton();
        btnBA = new javax.swing.JButton();
        btnDiferenciaSimetrica = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(jTable2);

        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane3.setViewportView(jTable3);

        jLabel1.setText("A={");

        jLabel2.setText("B={");

        jLabel3.setText("C={");

        btnUnion.setText("Union");
        btnUnion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUnionActionPerformed(evt);
            }
        });

        btnInterseccion.setText("Interseccion");
        btnInterseccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInterseccionActionPerformed(evt);
            }
        });

        btnAB.setText("A-B");
        btnAB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnABActionPerformed(evt);
            }
        });

        btnBA.setText("B-A");
        btnBA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBAActionPerformed(evt);
            }
        });

        btnDiferenciaSimetrica.setText("Diferencia Simetrica");
        btnDiferenciaSimetrica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDiferenciaSimetricaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnUnion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnInterseccion)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnAB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBA)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDiferenciaSimetrica))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel2)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnUnion)
                    .addComponent(btnInterseccion)
                    .addComponent(btnAB)
                    .addComponent(btnBA)
                    .addComponent(btnDiferenciaSimetrica))
                .addContainerGap(54, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void CargarConjuntoA(Conjunto Obj){
        for(int i=0;i<=3-1;i++){
            Entero ObjEntero = new Entero();
            ObjEntero.setNum(Integer.parseInt(jTable1.getValueAt(0, i).toString()));
            Obj.Insertar(ObjEntero);
        }
    }
    private void CargarConjuntoB(Conjunto Obj){
        for(int i=0;i<=3-1;i++){
            Entero ObjEntero = new Entero();
            ObjEntero.setNum(Integer.parseInt(jTable2.getValueAt(0, i).toString()));
            Obj.Insertar(ObjEntero);
        }
    }
    
    private void MostrarConjuntoC(Conjunto Obj){
        this.DimencionarResultado(Obj.getN());
        for(int i=0;i<=Obj.getN()-1;i++){
            jTable3.setValueAt(Obj.LeerVector(i).getNum(),0, i);
        }
    }
    private void btnUnionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUnionActionPerformed
        // TODO add your handling code here:
        Conjunto obja= new Conjunto();
        Conjunto objb= new Conjunto();
        Conjunto objc= new Conjunto();
        this.CargarConjuntoA(obja);
        this.CargarConjuntoB(objb);
        
        objc=objc.Union(obja, objb);
        this.MostrarConjuntoC(objc);
    }//GEN-LAST:event_btnUnionActionPerformed

    private void btnInterseccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInterseccionActionPerformed
        // TODO add your handling code here:
        Conjunto obja= new Conjunto();
        Conjunto objb= new Conjunto();
        Conjunto objc= new Conjunto();
        this.CargarConjuntoA(obja);
        this.CargarConjuntoB(objb);
        
        objc=objc.Interseccion(obja, objb);
        this.MostrarConjuntoC(objc);
        
    }//GEN-LAST:event_btnInterseccionActionPerformed

    private void btnABActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnABActionPerformed
        // TODO add your handling code here:
        Conjunto obja= new Conjunto();
        Conjunto objb= new Conjunto();
        Conjunto objc= new Conjunto();
        this.CargarConjuntoA(obja);
        this.CargarConjuntoB(objb);
        
        objc=objc.ARestaB(obja, objb);
        this.MostrarConjuntoC(objc);
    }//GEN-LAST:event_btnABActionPerformed

    private void btnBAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBAActionPerformed
        // TODO add your handling code here:
        Conjunto obja= new Conjunto();
        Conjunto objb= new Conjunto();
        Conjunto objc= new Conjunto();
        this.CargarConjuntoA(obja);
        this.CargarConjuntoB(objb);
        
        objc=objc.BRestaA(obja, objb);
        this.MostrarConjuntoC(objc);
    }//GEN-LAST:event_btnBAActionPerformed

    private void btnDiferenciaSimetricaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDiferenciaSimetricaActionPerformed
        // TODO add your handling code here:
        Conjunto obja= new Conjunto();
        Conjunto objb= new Conjunto();
        Conjunto objc= new Conjunto();
        this.CargarConjuntoA(obja);
        this.CargarConjuntoB(objb);        
        objc=objc.Union(obja.ARestaB(obja, objb), objb.BRestaA(obja, objb));
        this.MostrarConjuntoC(objc);
    }//GEN-LAST:event_btnDiferenciaSimetricaActionPerformed

    /**
     * @param args the command line arguments
     */
    
   
    private void DimencionarA(int CantidadColumna){
        DefaultTableModel modelo = new DefaultTableModel();       
        this.jTable1.setModel(modelo);
        for(int i=0;i<=CantidadColumna-1;i++){
            modelo.addColumn(Integer.toString(i));            
        }
        Object[] fila = new Object[1];
        modelo.addRow(fila);
    }
    private void DimencionarB(int CantidadColumna){
        DefaultTableModel modelo = new DefaultTableModel();       
        this.jTable2.setModel(modelo);
        for(int i=0;i<=CantidadColumna-1;i++){
            modelo.addColumn(Integer.toString(i));            
        }
        Object[] fila = new Object[1];
        modelo.addRow(fila);
    }
    
    private void DimencionarResultado(int nro){
        DefaultTableModel mo = new DefaultTableModel();
        this.jTable3.setModel(mo);
        for(int i=0;i<=nro-1;i++){
            mo.addColumn(Integer.toString(i));
        }
        Object[] f = new Object[1];
        mo.addRow(f);
    }
   
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmConjunto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAB;
    private javax.swing.JButton btnBA;
    private javax.swing.JButton btnDiferenciaSimetrica;
    private javax.swing.JButton btnInterseccion;
    private javax.swing.JButton btnUnion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    // End of variables declaration//GEN-END:variables
}
